<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/context/mytags.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>服务商商务派单</title>
    <t:base type="jquery,easyui,tools,DatePicker"></t:base>
    <link rel="stylesheet" href="plug-in/uploadify/css/uploadify.css" type="text/css"/>
    <script type="text/javascript" src="plug-in/ckfinder/ckfinder.js"></script>
    <script type="text/javascript" src="plug-in/uploadify/jquery.uploadify-3.1.min.js"></script>
    <script type="text/javascript" src="webpage/com/zybk/cbsservice/cbsServiceDispatchOrder.js"></script>
    <script>
        function callbackEng(data){
            if(data.success){
                window.top.$("#maintabs").tabs({
                    onBeforeClose : function(title,index){
                        try {
                            window.top.$("#maintabs").tabs('select','服务单管理');
                            window.top.tip(data.msg);
                            if(top.myTabWin.reloadTable()){
                                top.myTabWin.reloadTable();
                            }
                        } catch (e) {
                        } finally{
                            return true;
                        }
                    }
                });
                window.top.$("#maintabs").tabs('close','服务商区域工程师派单');
            }else{
                tip(data.msg);
            }
        }
        $(function(){
            $("select[name='assigningRoles']").change(function() {
                search();
            });
            //改变用户id，获取用户联系方式，工程师任务状态，工程师管理人数
            $("select[name='engNames']").change(function() {
                searchEngNames();
                $("#typename").val($("#engNames").find("option:selected").text());
            });
        })


        function search() {
            $.ajax({
                url: "cbsServiceController.do?queryEngineerForAppSendIp",
                data: {
                    "type": $("#assigningRoles").val(),
                    "planIds": $("#planIds").val(),
                    "company": $("#companyCode").val()
                },
                cache: false,
                dataType: 'json',
                type: 'POST',
                timeout: 2000,
                success: function(data) {
                    if(data.success) {
                        var list = data.obj;
                        $("#engNames").empty();
                        var ul_html = "";
                        ul_html = "<option value=''> -- 请选择人员 -- </option>";
                        $(list).each(function(i, item) {
                            ul_html += '<option value="' + item.id + '">' + item.name + '</option>';
                        });
                        $("#engNames").append(ul_html);
                    } else {
                        mui.toast(data.msg);
                    }
                }
            });
        }

        function searchEngNames() {
            var engnames = $("#engNames").val();
            $("#egId").val(engnames);
            $.ajax({
                url: "cbsServiceController.do?queryEngineerForAppEngName",
                data: {
                    "id": engnames
                },
                cache: false,
                dataType: 'json',
                type: 'POST',
                timeout: 2000,
                success: function(data) {
                    if(data.success) {
                        var rsData = data.attributes;
                        $("#egId").val(rsData.id); //工程师id
                        $("#phone").html(rsData.cellphone); //工程师电话
                        $("#providerId").val(rsData.dpid); /*服务商id*/
                        $("#assignTouserId").val(rsData.id); /*接单人id*/
                        $("#assignTorole").val(rsData.rolecode); /*接单人角色*/
                        $("#assignToroleId").val(rsData.roid); /*接单人角色id*/
                        $("#peopleSize").html(rsData.size); /*工程师管理人数*/
                        $("#num").html(rsData.wsize); /*工程师未完成个数*/
                    } else {
                        mui.toast(data.msg);
                    }
                }
            });
        }

        function checkcbsService(){
            var assigningRoles =$("#assigningRoles").val();
            var engNames = $("#engNames").val();
            if(assigningRoles==""||null==assigningRoles){
                tip("请选择分配人角色！");
                return false;
            }
            if(engNames==""||null==engNames){
                tip("请选择分配人员！");
                return false;
            }
        }

    </script>
</head>
<body>
<t:formvalid formid="generatePlan" action="cbsServiceAssignListController.do?findPeople" dialog="true" layout="table"
             tiptype="3" callback="callbackEng" beforeSubmit="checkcbsService">
    <div style="text-align: center;">共分配<span class="color-red">${planIdsArrsize}个</span>任务</div>
    <input type="hidden" name="planIds" id="planIds" value="${planIds}">
    <input type="hidden" name="providerId" id="providerId"> <%--服务商id--%>
    <input type="hidden" name="assignTouserId" id="assignTouserId">    <%--接单人id--%>
    <input type="hidden" name="assignTorole" id="assignTorole">    <%--接单人角色--%>
    <input type="hidden" name="assignToroleId" id="assignToroleId">    <%--接单人角色Id--%>
    <input type="hidden" name="companyCode" id="companyCode" value="${companyCode}">  <%--第三方服务商code--%>
    <input type="hidden" name="egId" id="egId" /><!--工程师id-->
    <input id="typename" type="hidden" name="typename">
    <table class="nobordertable noborder" style="border: none;">
        <tbody>
        <tr>
            <td class="al_r" width="30%">
                <label><label style="color: red;">*</label>分配给:</label>
            </td>
            <td width="70%">
                <select name="assigningRoles" id="assigningRoles">
                    <option value="">请选择角色</option>
                    <option value="3">工程师</option>
                </select>
                <br /><br />
                <select style="margin-bottom: 0px" name="engNames" id="engNames">
                </select>
            </td>
        </tr>
        <tr>
            <td class="al_r" width="30%" valign="top">
                <label>联系方式:</label>
            </td>
            <td width="70%">
                <span class="color-hui" id="phone"></span>
            </td>
        </tr>
        <tr>
            <td class="al_r" width="30%" valign="top">
                <label>工程师任务状态:</label>
            </td>
            <td width="70%">
                未完成：<span id="num"></span>
            </td>
        </tr>
        <tr>
            <td class="al_r" width="30%" valign="top">
                <label>工程师管理人员数:</label>
            </td>
            <td width="70%">
                <span id="peopleSize"></span>人
            </td>
        </tr>
        <tr>
            <td class="al_r" width="30%" valign="top">
                <label>备注信息:</label>
            </td>
            <td width="70%">
                <textarea style="width: 346px; height: 185px; margin: 0px;" id="reason" name="reason"></textarea>
            </td>
        </tr>
        </tbody>
    </table>
</t:formvalid>
</body>
</html>
